package org.sanm.domain.file;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.sanm.common.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;


@RestController
@Tag(name = "上传文件", description = "上传文件")
@RequestMapping("/file")
public class FileController {
    @Value("${file.prefix}")
    private String prefix;
    @Value("${file.path}")
    private String path;
    @Autowired
    FileService fileService;

    @PostMapping(value = "/upload", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
    @Operation(summary = "上传文件", description = "上传文件")
    public Result<String> upload(@RequestPart MultipartFile file) throws Exception {


        return Result.success(fileService.uploadFile(file));
    }


}
